package com.lonwin.inspectionmanagement.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.R2;
import com.lonwin.inspectionmanagement.app.AppConstants;
import com.lonwin.inspectionmanagement.di.component.DaggerUpcomingListComponent;
import com.lonwin.inspectionmanagement.mvp.contract.UpcomingListContract.View;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.UpcommingBean;
import com.lonwin.inspectionmanagement.mvp.presenter.UpcomingListPresenter;
import com.lonwin.inspectionmanagement.mvp.ui.adapter.UpcomingListAdapter;
import com.lonwin.inspectionmanagement.widget.dialog.LoadingDailog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 12/25/2018 21:49
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class UpcomingListActivity extends BaseActivity<UpcomingListPresenter> implements View {

    @BindView(R2.id.back_icon)
    ImageView backIcon;
    @BindView(R2.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R2.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R2.id.back_right_icon)
    TextView backRightIcon;
    @BindView(R2.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R2.id.toolbar)
    Toolbar toolbar;
    @BindView(R2.id.UpcomingList_RecyclerView)
    RecyclerView UpcomingListRecyclerView;
      private UpcomingListAdapter upcomingListAdapter;
    private LoadingDailog loadingDailog;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerUpcomingListComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_upcoming_list; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        loadingDailog=new LoadingDailog.Builder(this).setMessage("数据获取中...").create();
        UpcomingListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        upcomingListAdapter=new UpcomingListAdapter(new ArrayList<>(),mPresenter.getConfigBean());
        upcomingListAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
        UpcomingListRecyclerView.setAdapter(upcomingListAdapter);


    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mPresenter.getConfigBean().getCurrentRole().getRoleCode().equals(AppConstants.ROLE_LLY)||mPresenter.getConfigBean().getCurrentRole().getRoleCode().equals(AppConstants.ROLE_LDBM))
        {
            toolbarTitle.setText("待办事项");
        }else {
            toolbarTitle.setText("审批事项");
        }
        mPresenter.getBacklogXcjlb();
    }

    @Override
    public void showLoading() {
   loadingDailog.show();
    }

    @Override
    public void hideLoading() {
        loadingDailog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Activity getMyActivity() {
        return this;
    }

    @Override
    public void getBacklogXcjlbSuccess(List<UpcommingBean.DataBean> dataBean) {
        upcomingListAdapter.setNewData(dataBean);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
